<template>
  <div class="addAdmin">
    <el-card shadow="never" style="margin-top: 30px">
      <div class="header">
        <div class="page-header">
          <el-page-header @back="goBack" content="添加管理员" style="margin-bottom: 20px">
          </el-page-header>
        </div>

      <!--  添加管理员  -->
        <div class="add-center">
          <el-form :model="adminForm" :rules="adminRules" ref="adminForm" label-width="100px" class="demo-ruleForm" size="mini">
            <el-form-item label="账号" prop="adminPhone">
              <el-input v-model="adminForm.adminPhone"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="adminPassword" >
              <el-input v-model="adminForm.adminPassword" show-password></el-input>
            </el-form-item>
            <el-form-item label="姓名" prop="adminName">
              <el-input v-model="adminForm.adminName"></el-input>
            </el-form-item>

            <el-form-item label="性别" prop="adminSex">
                <el-radio-group v-model.number="adminForm.adminSex">
                  <el-radio :label="1">男</el-radio>
                  <el-radio :label="0">女</el-radio>
                </el-radio-group>
            </el-form-item>

            <el-form-item label="所属部门" prop="adminDepart">
              <el-select v-model.number="adminForm.adminDepart" placeholder="请选择所属部门">
                <el-option label="村委" value="村委"></el-option>
                <el-option label="宣传部" value="宣传部"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="addAdmin()">确定添加</el-button>
              <el-button @click="resetForm(adminForm)">重置</el-button>
            </el-form-item>
          </el-form>
        </div>

      </div>
    </el-card>
  </div>
</template>

<script>
import {addAdmin} from "@/api/allApi";

export default {
  name: "AddAdmin",
  data() {
    return {
      adminForm: {
        adminPhone:'',
        adminPassword:'',
        adminName:'',
        adminSex:'',
        adminDepart:''
      },
      adminRules: {
        adminPhone:[
          { required: true, message: '请输入手机号', trigger: 'blur' },
        ],
        adminPassword:[
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
        adminName:[
          { required: true, message: '请输入姓名', trigger: 'blur' },
        ],
        adminSex:[
          { required: true, message: '性别', trigger: 'blur' },
        ],
        adminDepart:[
          { required: true, message: '请选择部门', trigger: 'blur' },
        ]
      }
    };
  },
  mounted() {

  },
  methods: {
    resetForm() {

    },
    goBack() {
      this.$router.back();
    },
    addAdmin(){
      addAdmin(
        this.adminForm
      ).then(res=>{
        if (res.data.success){
          this.$message({
            message: '添加成功',
            type: 'success'
          });
          this.$router.push({
            name: "adminManage"
          });
        }else {
          this.$message.warning(res.data.errorMsg)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
  .addAdmin{
    .add-center {
      width: 700px;
      padding: 30px;
    }

  }
</style>